package ws.performancetest.app.gui.dialog;

import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;

/**
 *
 * @author Wilson Santos, 36228 <wilson.santos@ua.pt>
 */
public class ChooseFileDialog extends javax.swing.JDialog {

  private static final ChooseFileDialog reference;

  static {
    reference = new ChooseFileDialog(new javax.swing.JFrame(), true);
    reference.addWindowListener(new java.awt.event.WindowAdapter() {

      @Override
      public void windowClosing(java.awt.event.WindowEvent e) {
        System.exit(0);
      }
    });
  }

  /** Creates new form ChooseFileDialog */
  public ChooseFileDialog(java.awt.Frame parent, boolean modal) {
    super(parent, modal);
    initComponents();
  }

  public static ChooseFileDialog getReference() {
    return reference;
  }

  /** This method is called from within the constructor to
   * initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is
   * always regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    jFileChooser1 = new javax.swing.JFileChooser();

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

    jFileChooser1.setDialogTitle("");
    jFileChooser1.setFileFilter(new FileNameExtensionFilter("SQL files", "sql"));
    jFileChooser1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jFileChooser1ActionPerformed(evt);
      }
    });

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jFileChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jFileChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    );

    pack();
  }// </editor-fold>//GEN-END:initComponents

    private void jFileChooser1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jFileChooser1ActionPerformed
      reference.setVisible(false);
    }//GEN-LAST:event_jFileChooser1ActionPerformed

  /**
   * @param args the command line arguments
   */
  public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {

      public void run() {
        getReference().setVisible(true);
      }
    });
  }
  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JFileChooser jFileChooser1;
  // End of variables declaration//GEN-END:variables

  /**
   * Get the JFileChooser of this dialog.
   *
   * @return JFileChooser reference of this dialog.
   */
  public static JFileChooser getFileChooser() {
    return reference.jFileChooser1;
  }

  public static int showOpenDialog() {
    return reference.jFileChooser1.showOpenDialog(reference);
  }
}
